package com.xiaowen.dataProcessing;

import com.xiaowen.dataProcessing.dto.*;
import com.xiaowen.tool.HttpTool;
import com.xiaowen.tool.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;

@Component
@Slf4j
public class DataProcessingApi {

    private final static String DATA_PROCESSING_URL = "https://xiaowenai.com.cn/py/";

    //编码
    public final static String GENERATE_LABEL = "generate_label";
    //
    public final static String GENERATE_LABEL_WITH_EXAMPLE = "generate_label_with_example";
    //
    public final static String GENERATE_NET_NAME = "generate_net_name";
    //
    public final static String MATCH_NET_NAME = "match_net_name";
    //
    public final static String SIMILAR_COMBINE = "similar_combine";

    //model
    public final static String MODEL_DEEPSEEK = "deepseek";
    public final static String MODEL_DEEPSEEK_CHAT = "deepseek-chat";


    public static GenerateLabelRespDTO generateLabel(GenerateLabelReqDTO generateLabelReqDTO){
        try {
            log.info(GENERATE_LABEL+"参数:{}", JsonUtils.toJson(generateLabelReqDTO));
            String result = HttpTool.postByJson(DATA_PROCESSING_URL+GENERATE_LABEL, generateLabelReqDTO);
            log.info(GENERATE_LABEL+"返回参数:{}", result);
            GenerateLabelRespDTO respDTO = JsonUtils.toBean(result, GenerateLabelRespDTO.class);
            return respDTO;
        }catch (Exception e){
            log.error(GENERATE_LABEL+"方法错误:{}", e);
        }
        return null;
    }

    public static GenerateLabelRespDTO generateLabelWithExample(GenerateLabelReqDTO generateLabelReqDTO){
        try {
            log.info(GENERATE_LABEL_WITH_EXAMPLE+"参数:{}", JsonUtils.toJson(generateLabelReqDTO));
            String result = HttpTool.postByJson(DATA_PROCESSING_URL+GENERATE_LABEL_WITH_EXAMPLE, generateLabelReqDTO);
            log.info(GENERATE_LABEL_WITH_EXAMPLE+"返回参数:{}", result);
            GenerateLabelRespDTO respDTO = JsonUtils.toBean(result, GenerateLabelRespDTO.class);
            return respDTO;
        }catch (Exception e){
            log.error(GENERATE_LABEL_WITH_EXAMPLE+"方法错误:{}", e);
        }
        return null;
    }

    public static List<String> generateNetName(GenerateNetReqDTO generateNetReqDTO){
        try {
            log.info(GENERATE_NET_NAME+"参数:{}", JsonUtils.toJson(generateNetReqDTO));
            String result = HttpTool.postByJson(DATA_PROCESSING_URL+GENERATE_NET_NAME, generateNetReqDTO);
            log.info(GENERATE_NET_NAME+"返回参数:{}", result);
            List<String> netNameList = JsonUtils.toBean(result, List.class);
            return netNameList;
        }catch (Exception e){
            log.error(GENERATE_NET_NAME+"方法错误:{}", e);
        }
        return null;
    }

    public static List<MatchNetNameRespDTO> matchNetName(GenerateNetReqDTO generateNetReqDTO){
        try {
            log.info(MATCH_NET_NAME+"参数:{}", JsonUtils.toJson(generateNetReqDTO));
            String result = HttpTool.postByJson(DATA_PROCESSING_URL+MATCH_NET_NAME, generateNetReqDTO);
            log.info(MATCH_NET_NAME+"返回参数:{}", result);
            List<MatchNetNameRespDTO> nameRespDTOList = JsonUtils.toCollectionBean(result, List.class, MatchNetNameRespDTO.class);
            return nameRespDTOList;
        }catch (Exception e){
            log.error(MATCH_NET_NAME+"方法错误:{}", e);
        }
        return null;
    }


    public static List<SimilarCombineRespDTO> similarCombine(SimilarCombineReqDTO similarCombineReqDTO){
        try {
            log.info(SIMILAR_COMBINE+"参数:{}", JsonUtils.toJson(similarCombineReqDTO));
            String result = HttpTool.postByJson(DATA_PROCESSING_URL+SIMILAR_COMBINE, similarCombineReqDTO);
            log.info(SIMILAR_COMBINE+"返回参数:{}", result);
            List<SimilarCombineRespDTO> combineRespDTOList = JsonUtils.toCollectionBean(result, List.class, SimilarCombineRespDTO.class);
            return combineRespDTOList;
        }catch (Exception e){
            log.error(SIMILAR_COMBINE+"方法错误:{}", e);
        }
        return null;
    }
}
